package map.water;

import java.util.Scanner;

public class Main {
    static int[][] dir = new int[][]{{0,1},{1,0},{-1,0},{0,-1}};
    public static void dfs(int[][] grid, boolean[][] visited, int x, int y){
        if (visited[x][y]){
            return;
        }
        visited[x][y] = true;
        for (int i = 0; i < 4; i++) {
            int nextX = x + dir[i][0];
            int nextY = y + dir[i][1];
            if (nextX < 0 || nextY < 0 || nextX >= grid.length || nextY >= grid[0].length){
                continue;
            }
            if (grid[nextX][nextY] < grid[x][y]){
                continue;
            }
            dfs(grid, visited, nextX, nextY);
        }

    }
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int rows = sc.nextInt();
        int cols = sc.nextInt();
        int[][] grid = new int[rows][cols];
        for (int i = 0; i < rows; i++) {
            for (int j = 0; j < cols; j++) {
                grid[i][j] = sc.nextInt();
            }
        }
        boolean[][] first = new boolean[rows][cols];
        boolean[][] second = new boolean[rows][cols];
        for (int i = 0; i < rows; i++) {
            dfs(grid, first, i, 0);
            dfs(grid, second, i, cols - 1);
        }
        for (int i = 0; i < cols; i++) {
            dfs(grid, first, 0, i);
            dfs(grid, second, rows - 1, i);
        }
        for (int i = 0; i < rows; i++) {
            for (int j = 0; j < cols; j++) {
                if (first[i][j] && second[i][j]){
                    System.out.println(i + " " + j);
                }
            }
        }
    }
}
